
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="author" content="ljc">
    <title></title>
    <script src="js/jquery-3.1.1.js">
        
    </script>
    <style>
    body{
        
        background-color: powderblue;
        position: relative;
    }
    div{
        width: 100%;
        height: 2000px;
    }
    ul{
        position: absolute;
        right:0;
    }
        ul,li{

            padding: 0;
            margin: 0;
            list-style: none;
        }
        li{
            position: relative;
            margin: 10px 0;
            /*overflow: hidden;*/
        }
        span{
            display: inline-block;
            width: 15px;
            height: 50px;
            background-color: lightsteelblue;
            line-height: 50px;
            text-align: center;            
        }
        a{
            text-decoration: none;
            top:0;
            position: absolute;
            left:100px;
            display: inline-block;
            width: 100px;
            height: 50px;
            font-size: 16px;
            background-color: lightskyblue;
            line-height: 50px;
            opacity: 0.8;
            color: white;
            padding-left:10px;
            border-top-left-radius:25px;
            border-bottom-left-radius:25px;
            display: none;
        }
    </style>
</head>
<body>
    <div>
        
    </div>
    <ul>
        <li><span>t</span><a id="a" href="javascript:;" >返回顶部</a></li>
        <li><span>f</span><a id="b" href="javascript:;">转到底部</a></li>
    </ul>
</body>
</html>
<script>

setCenter();
function setCenter(){
    var top = ($(window).height()-$('ul').height())/2+$(document).scrollTop();
    $('ul').css('top',top)
}
$(window).scroll(function(){
    setCenter();
})
$('li').each(function(index){
    $(this).hover(function(){
        $('a',this).show().css('left',-95);
    },function(){
        $('a',this).hide();
    })
    
})
$('#a').click(function(){
    $('html,body').animate({
        scrollTop:0,
    },800)
})

$('#b').click(function(){
    $('html,body').animate({
        scrollTop:$(document).height(),
    },800)
})

</script>